import React from 'react'
import cx from 'classnames'
import style from './style.radioGroup'
import Radio from './Radio'

class RadioGroup extends React.Component {

  handleChange(e) {
    this.props.onChange(e.target.value)
  }

	render() {
    const { disabled, data, name, className } = this.props
		return (
      <div className={cx({
        [style.root]: true,
        [className]: className
      })}>
        {
          data.map(({label, value, checked}, i) => {
            return (
              <Radio 
                disabled={disabled}
                checked={checked}
                value={value} 
                onChange={::this.handleChange} name={name} 
                key={i} 
                label={label}
              />
            )
          })
        }
      </div>
		)
	}
}

export default RadioGroup
